/**
 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

% columns = %w(Instruction Destination Inputs Properties Verification Description)
| <%= columns.join(' | ') %> |
| <%= '---|' * columns.size %>
<%
null_check_users = IR::instructions.select { |x| x.operands.any? { |o| o.tokens.include? Tokens::Other::NULL_CHECK}}
zero_check_users = IR::instructions.select { |x| x.operands.any? { |o| o.tokens.include? Tokens::Other::ZERO_CHECK}}
bounds_check_users = IR::instructions.select { |x| x.operands.any? { |o| o.tokens.include? Tokens::Other::BOUNDS_CHECK}}
negative_check_users = IR::instructions.select { |x| x.operands.any? { |o| o.tokens.include? Tokens::Other::NEGATIVE_CHECK}}

IR::instructions.each do |inst|
  dest = inst.has_dst? ? inst.operands.first.types.join(', ') : ''
  inputs = inst.has_inputs? ? "<ul><li> #{inst.inputs.map {|x| x.types_string }.join('</li><li>') } </li></ul>" : ''
  verify = (inst.respond_to? 'verification') ? inst.verification : []
  case inst.opcode
  when 'NullCheck'
    verify << "users.contain(#{ null_check_users.map { |x| x.opcode }.join(', ')})"
  when 'ZeroCheck'
    verify << "users.contain(#{ zero_check_users.map { |x| x.opcode }.join(', ')})"
  when 'BoundsCheck'
    verify << "users.contain(#{ bounds_check_users.map { |x| x.opcode }.join(', ')})"
  when 'NegativeCheck'
    verify << "users.contain(#{ negative_check_users.map { |x| x.opcode }.join(', ')})"
  end
  verify_str = !verify.empty? ? "<ul><li> #{verify.join('</li><li>') } </li></ul>" : ''
-%>
| <%= inst.opcode %> | <%= dest %> | <%= inputs %> | <%= inst.flags.join(', ') %> | <%= verify_str %> | <%= inst.description %> |
% end

### Legend:
% IR::legend.each_pair do |chapter, values|
**<%= chapter %>**
%   values.each_pair do |key, value|
- <font color="green"><%= key %></font>: <%= value %>
%   end

% end